from selenium.webdriver.common.by import By

from pom.base import BaseDriver

class UserCompetationPage(BaseDriver):

    def __init__(self, driver):
        super(UserCompetationPage, self).__init__(driver)

    """ 参赛须知 """
    # 参赛须知中的竞赛名称
    _confirm_title = By.XPATH, '//div[@class="f-fs-20 f-fwb f-tac"]'


    # 参赛须知中的竞赛时间
    _confirm_time = By.XPATH, '//div[@class="f-fs-16 f-m-t-10 f-tac"]'

    # 参赛须知中的须知内容
    _confirm_text = By.XPATH, '//div[@class="f-m-t-20 markdown-body f-p-20 confirm-text"]//p'

    # 参赛须知勾选框
    _confirm_checkbox = By.XPATH, '//span[@class="el-checkbox__inner"]'

    # 参赛须知确认提交按钮
    _confirm_button = By.XPATH, '//span[text()="确认提交"]/..'

    """ 竞赛页面 """
    # 竞赛标题
    _title = By.XPATH, '//div[@class="title f-m-t-20 f-fwb f-wwb"]/span[1]'

    # 竞赛状态
    _status = By.XPATH, '//span[@class="f-m-l-10 el-tag el-tag--danger el-tag--light"]'

    # 查看简介
    _check_desc = By.XPATH, '//span[@class="f-m-r-10"]'

    # 简介内容
    _desc_text = By.XPATH, '//div[@class="comp-desc text-color f-wwb f-m-t-20 line-height-25"]/span[2]'

    # 简介框中的确定按钮
    _desc_confirm = By.XPATH, '//button[@class="el-button el-button--default el-button--small el-button--primary "]'

    # 相关镜像  可能有多个
    _image = By.XPATH, '//div[@class="comp-image"]/span[2]'

    # 其他附件  可能有多个
    _file = By.XPATH, '//div[@class="file"]//span'

    # 其他说明
    _other_desc = By.XPATH, '//div[@class="f-m-t-10 f-wwb line-height-25"]'

    """ 答题 """

    # 题目
    def question(self, num):
        path = By.XPATH, '//div[@class="f-m-t-10 el-col el-col-6"][{}]//div[@class="el-card__body"]'.format(num)
        ele = self.find_ele(*path)
        self.logger.info("第{}题".format(num))
        return ele

    # 选项（单选、多选）
    def option(self, value):
        path = By.XPATH, '//input[@value = "{}"]/..'.format(value)
        ele = self.find_ele(*path)
        self.logger.info("选择{}".format(value))
        return ele
    # 填空题答题框
    _textarea = By.XPATH, '//div[@class="input-box f-w-full f-m-t-10"]//textarea'
    # 主观题答题框
    _subjective_textarea = By.XPATH,'//textarea'
    # 下一题
    _next_question = By.XPATH, '//div[@class="next f-csp"]'

    # 上一题
    _front_question = By.XPATH, '//div[@class="pre f-csp"]'

    # 提交答案
    # _submit_answer = By.XPATH, '//button[@class="el-button el-button--primary is-round"]'
    _submit_answer = By.XPATH, '//span[text()="提交答案"]/..'
    # 置灰的提交答案按钮
    _disabled_submit_button = By.XPATH, '//button[@class="el-button el-button--primary is-disabled is-round"]'



    # 题目类型
    _question_type = By.XPATH, '//div[@class="f-fs-20 f-fwb f-tac f-m-b-20"]'

    # 题号
    _question_num = By.XPATH, '//span[@class="f-fs-16 f-fwb"]'

    # 结束答题
    _stop_button = By.XPATH, '//span[text()="结束答题"]/..'

    # 有题目没有作答，提交前的确认框
    _unfinished_num = By.XPATH, '//div[@class="el-message-box__message"]/p'

    _unfinished_confirm_button = By.XPATH, '//button[@class="el-button el-button--default el-button--small el-button--primary "]'

    # 结束确认框中的 本次竞赛的名称
    _stop_confirm_name = By.XPATH, '//span[@class="f-fwb f-fc-333 f-m-r-10"]'

    # 结束确认框中的 输入竞赛名称框
    _stop_name_text = By.XPATH, '//input[@placeholder="请输入本次竞赛名称"]'

    # 确认按钮
    _stop_confirm_button = By.XPATH, '//span[text()="确定"]'

    _frequent_operation = By.XPATH, '//p[text()="您的操作过于频繁，请稍后再试！"]'

    @property
    def unfinished_confirm_button(self):
        ele = self.find_ele(*self._unfinished_confirm_button)
        return ele

    @property
    def unfinished_num(self):
        ele = self.find_ele(*self._unfinished_num)
        return ele

    @property
    def frequent_operation(self):
        ele = self.find_ele(*self._frequent_operation)
        return ele
    @property
    def stop_name_text(self):
        ele = self.find_ele(*self._stop_name_text)
        return ele
    @property
    def stop_confirm_button(self):
        ele = self.find_ele(*self._stop_confirm_button)
        return ele
    @property
    def stop_confirm_name(self):
        ele = self.find_ele(*self._stop_confirm_name)
        return ele

    @property
    def stop_button(self):
        ele = self.find_ele(*self._stop_button)
        return ele

    @property
    def question_num(self):
        ele = self.find_ele(*self._question_num)
        return ele



    @property
    def question_type(self):
        ele = self.find_ele(*self._question_type)
        return ele

    # 填空题
    @property
    def textarea(self):
        ele = self.find_ele(*self._textarea)
        return ele

    @property
    def subjective_textarea(self):
        ele = self.find_ele(*self._subjective_textarea)
        return ele

    @property
    def next_question(self):
        ele = self.find_ele(*self._next_question)
        return ele

    @property
    def front_question(self):
        ele = self.find_ele(*self._front_question)
        return ele

    @property
    def submit_answer(self):
        ele = self.find_ele(*self._submit_answer)
        return ele


    @property
    def confirm_title(self):
        ele = self.find_ele(*self._confirm_title)
        self.logger.info("参赛须知中的竞赛标题")
        return ele

    @property
    def confirm_time(self):
        ele = self.find_ele(*self._confirm_time)
        self.logger.info("参赛须知中的竞赛标题")
        return ele

    @property
    def confirm_text(self):
        ele = self.find_ele(*self._confirm_text)
        self.logger.info("参赛须知内容")
        return ele

    @property
    def confirm_checkbox(self):
        ele = self.find_ele(*self._confirm_checkbox)
        self.logger.info("参赛须知勾选框")
        return ele

    @property
    def confirm_button(self):
        ele = self.find_ele(*self._confirm_button)
        self.logger.info("参赛须知确认框")
        return ele

    @property
    def title(self):
        ele = self.find_ele(*self._title)
        self.logger.info("竞赛标题")
        return ele

    @property
    def status(self):
        ele = self.find_ele(*self._status)
        self.logger.info("竞赛状态")
        return ele

    @property
    def check_desc(self):
        ele = self.find_ele(*self._check_desc)
        self.logger.info("查看简介")
        return ele

    @property
    def desc_text(self):
        ele = self.find_ele(*self._desc_text)
        self.logger.info("简介内容")
        return ele

    @property
    def desc_confirm(self):
        ele = self.find_ele(*self._desc_confirm)
        self.logger.info("简介框中的确定按钮")
        return ele

    @property
    def image(self):
        ele = self.find_eles(*self._image)
        self.logger.info("相关镜像")
        return ele

    @property
    def file(self):
        ele = self.find_ele(*self._file)
        self.logger.info("其他附件")
        return ele

    @property
    def other_desc(self):
        ele = self.find_ele(*self._other_desc)
        self.logger.info("其他说明")
        return ele
